package com.jy.admin.rest.sms;

import com.jy.admin.db.entity.SmsTemplateEntity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2021/12/16
 * Time: 10:47 上午
 */
public class TemplateListResponse implements Serializable {
    private static final long serialVersionUID = -4396219482191170615L;

    private Map<String, List<Item>> map = new HashMap<>();

    public TemplateListResponse(List<SmsTemplateEntity> allTemplates) {

        allTemplates.forEach(templateEntity -> {

            if (!map.containsKey(templateEntity.getProvider())) {
                map.put(templateEntity.getProvider(), new ArrayList<>());
            }

            List<Item> items = map.get(templateEntity.getProvider());
            items.add(new Item().setCode(templateEntity.getTemplateNo())
                    .setName(templateEntity.getName()));

            map.put(templateEntity.getProvider(),items);
        });
    }

    public Map<String, List<Item>> getMap() {
        return map;
    }

    public TemplateListResponse setMap(Map<String, List<Item>> map) {
        this.map = map;
        return this;
    }

    private class Item {

        private String code;
        private String name;

        public String getCode() {
            return code;
        }

        public Item setCode(String code) {
            this.code = code;
            return this;
        }

        public String getName() {
            return name;
        }

        public Item setName(String name) {
            this.name = name;
            return this;
        }
    }
}
